package de.g18.llmaa.gui.workspace.internalFrame.dbAbgleich;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JPanel;

import de.g18.llmaa.gui.App_LLMAA_Controler;
import de.g18.llmaa.gui.App_Model_Database;
import de.g18.llmaa.gui.workspace.Workspace_Crtl;
import de.g18.llmaa.logic.db.HSQLDBConnect;
import de.g18.llmaa.logic.vos.VOProduct_Key;

public class JPanel_DB_Abgleich_Step_2 extends JPanel {

	private JPanel panel_South;
	private JButton button_Abgleich;
	private JButton button_Model_Schwenk;
	
	private ArrayList<VOProduct_Key> listProducts;

	public JPanel_DB_Abgleich_Step_2(ArrayList<VOProduct_Key> listProducts) {
		this.listProducts = listProducts;

	initGUI();
	
	}

	private void initGUI() {
		setLayout(new BorderLayout());
		add(getPanel_South(),BorderLayout.SOUTH);
	}

	public JPanel getPanel_South() {
		if(panel_South==null)
		{
			panel_South = new JPanel();
			panel_South.add(getButton_Abgleich());
			panel_South.add(getButton_Model_Schwenk());
		}
				
		return panel_South;
	}

	public JButton getButton_Abgleich() {
		if(button_Abgleich==null)
		{
			button_Abgleich = new JButton("Abgleichen");
			button_Abgleich.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					HSQLDBConnect db;
					try {
						
						HSQLDBConnect.getInstanze().initDatabase();
						HSQLDBConnect.getInstanze().saveVOPoduct_KeyList(listProducts);
						System.out.println(HSQLDBConnect.getInstanze().selectAllProducts().size());
//						db.shutdown();
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				
					
				}
			});
		}
		return button_Abgleich;
	}

	public JButton getButton_Model_Schwenk() {
		if(button_Model_Schwenk==null)
		{
			button_Model_Schwenk = new JButton("Auf DB Schwenken");
			
			
			button_Model_Schwenk.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					HSQLDBConnect db;
					try {
						
//						db.initDatabase();
//						db.saveVOPoduct_KeyList(listProducts);
						HSQLDBConnect.getInstanze();
						System.out.println(HSQLDBConnect.getInstanze().selectAllProducts().size()+"dasdas");
//						db.shutdown();
						
						App_LLMAA_Controler.getInstanze().setModel(new App_Model_Database());
						
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				
					
				}
			});
		}
		return button_Model_Schwenk;
	}
	
	
	
	
	

}
